<?php

namespace app\admin\model;

use think\Model;

class Fangyuan extends Model
{
    // 表名
    protected $name = 'fangyuan';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;

    // 追加属性
    protected $append = [
        'state_text',
        'zl_type_text',
        'zl_starttime_text',
        'zl_endtime_text'
    ];



    public function getStateList()
    {
        return ['1' => __('State 1'),'2' => __('State 2'),'3' => __('State 3'),'4' => __('State 4'),'5' => __('State 5'),'6' => __('State 6'),'7' => __('State 7')];
    }

    public function getZlTypeList()
    {
        return ['1' => __('Zl_type 1'),'2' => __('Zl_type 2'),'3' => __('Zl_type 3')];
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : $data['state'];
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getZlTypeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['zl_type'];
        $list = $this->getZlTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getZlStarttimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['zl_starttime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getZlEndtimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['zl_endtime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setZlStarttimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setZlEndtimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


    public function rent()
    {
        return $this->belongsTo('rent');
    }
}
